#pragma once
#ifndef SOFTSERIAL_H
#define SOFTSERIAL_H

#include <Arduino.h>

#define BUFFER_SIZE 128 //Number of bytes to store in a buffer

class _SoftSerial{
private:
  void _Timer1InterruptRoutine();
  void _Int0InterruptRoutine();
  byte buf[BUFFER_SIZE];  //buffer to store received bytes
  byte _i;                //current bit
  byte _b;                //shift byte to store current byte
  byte _ptrRead;          //position in buffer to read from          
  byte _ptrWrite;         //position in buffer to write to
  int _baud;              //period of each bit in instruction cycles
public:
  void begin(int baud);
  int  read(void);
  int  available(void);
  int  peek(void);
  void clear(void);
};

extern _SoftSerial SoftSerial;

#endif

